<template>
  <div id="main-page-container">
    <el-container>
      <el-header class="header_jy">
        <div class="logo">
          <el-image :src="logoPath" alt="疆屿logo"></el-image>
        </div>
        <div id="system-name">疆屿后台管理系统</div>
        <div class="user-info">
          <span
            >欢迎，<span class="username-span">{{ username }}</span></span
          >
          <button @click="exit" class="exit-btn">退出登录</button>
        </div>
      </el-header>
      <el-container>
        <el-aside width="200px" class="aside-menu">
          <el-radio-group v-model="isCollapse" style="margin-bottom: 20px">
            <el-radio-button :label="false">展开</el-radio-button>
            <el-radio-button :label="true">收起</el-radio-button>
          </el-radio-group>
          <el-menu
            default-active="1-4-1"
            class="el-menu-vertical-demo"
            @open="handleOpen"
            @close="handleClose"
            :collapse="isCollapse"
          >
            <el-submenu index="1">
              <template>
                <i class="el-icon-location"></i>
                <span>导航一</span>
              </template>
              <el-menu-item-group>
                <span>分组一</span>
                <el-menu-item index="1-1">选项1</el-menu-item>
                <el-menu-item index="1-2">选项2</el-menu-item>
              </el-menu-item-group>
              <el-menu-item-group title="分组2">
                <el-menu-item index="1-3">选项3</el-menu-item>
              </el-menu-item-group>
              <el-submenu index="1-4">
                <span>选项4</span>
                <el-menu-item index="1-4-1">选项1</el-menu-item>
              </el-submenu>
            </el-submenu>
            <el-menu-item index="2">
              <i class="el-icon-menu"></i>
              <span>导航二</span>
            </el-menu-item>
            <el-menu-item index="3" disabled>
              <i class="el-icon-document"></i>
              <span >导航三</span>
            </el-menu-item>
            <el-menu-item index="4">
              <i class="el-icon-setting"></i>
              <span>导航四</span>
            </el-menu-item>
          </el-menu>
        </el-aside>
        <el-main class="content-area">
          <!-- <router-view></router-view> -->
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import { mapActions } from "vuex";
export default {
  name: "MainPage",
  data() {
    return {
      logoPath: require("@/assets/imgs/jylogo.png"),
      username: "", // 用户名
      isCollapse: true,
    };
  },
  created() {
    // console.log(localStorage.getItem('token'));
    // console.log(localStorage.getItem('username'));
    this.username = localStorage.getItem("username");
    console.log(this.$router.options.routes);
  },
  methods: {
    ...mapActions(["logout"]),

    // 退出登录
    exit() {
      // console.log('退出')
      this.$confirm("确定要退出吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          // 调用vuex里的logout方法
          this.logout();
          // 还可以进行页面跳转，例如跳转到登录页面
          this.$router.push("/login");
        })
        .catch(() => {
          // 用户点击取消后执行的逻辑，这里可以什么都不做或者做一些提示等操作
          console.log("用户取消了退出操作");
        });
    },

    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
  },
};
</script>

<style lang="scss" scoped>
#main-page-container {
  width: 100vw;
  height: 100vh;
  background-color: #3b89952d;
}
.header_jy {
  background-color: #85bcbb2d;
  display: flex;
  justify-content: space-between;
  align-items: center;

  #system-name {
    font-size: 30px;
    letter-spacing: 3px;
    font-weight: 600;
  }
}

.username-span {
  font-size: 24px;
  margin-right: 20px;
  color: #01c6c1;
}

.exit-btn {
  border-radius: 30px;
  width: 100px;
  height: 35px;
}

.active-class {
  background-color: #f40e81;
}

.aside-menu {
  background-color: #6b6594;
}

.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 200px;
  min-height: 400px;
}
</style>
